package com.jackson.framekafka.controller;

/*
 * Author: JacksonCoder
 * FileName: KafkaController
 * Version: 1.0.0
 * Date: 2025/4/13
 */

import com.jackson.framekafka.service.KafkaProduce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/kafka")
public class KafkaController {

    @Autowired
    private KafkaProduce kafkaProduce;

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @PostMapping("/send")
    public String send(@RequestParam String message) {
        kafkaProduce.sendMessage(message);
        System.out.println("this method is run");

        return "Message sent to Kafka" + message;
    }

    @GetMapping("sendmsg")
    public String sendMessage() {
        for (int i = 0; i < 10000; i++) {
            kafkaTemplate.send("item_topic", "测试消息" + i);
        }
        return "success";
    }


}
